#include <stdio.h>
#include <stdlib.h>

#include <string>
#include <iostream>
using namespace std;

struct LoginEntity
{
    string name;
    int age;
} LoginSt;

LoginEntity get_user()
{
    LoginEntity entity;
    entity.name = "tom1";
    entity.age = 11;
    return entity;
}

LoginEntity & get_user1()
{
    LoginEntity entity;
    entity.name = "tom1333";
    entity.age = 113333;
    return entity;
}

LoginEntity & get_user2(LoginEntity & entity)
{
    entity.name = "tom2";
    entity.age = 22;
    return entity;
}

void get_user22(LoginEntity & entity)
{
    entity.name = "tom2";
    entity.age = 22;
}

void get_user3(LoginEntity * entity)
{
    entity->name = "tom3";
    entity->age = 33;
}

LoginEntity * get_user4()
{
    LoginEntity * entity = new LoginEntity();
    entity->name = "tom4";
    entity->age = 44;
    return entity;
}

void get_user5(LoginEntity ** entity)
{
    LoginEntity * entity3 = new LoginEntity();
    entity3->name = "tom5";
    entity3->age = 55;
    *entity = entity3;
}

int main()
{
    LoginEntity entity = get_user();
    cout << "name:" << entity.name << endl;
    cout << "age:" << entity.age << endl;

    // LoginEntity entity1 = get_user1();
    // cout << "name1:" << entity1.name << endl;
    // cout << "age1:" << entity1.age << endl;

    LoginEntity entity2;
    LoginEntity entity21;
    entity21 = get_user2(entity2);
    cout << "name2:" << entity2.name << endl;
    cout << "age2:" << entity2.age << endl;
    cout << "name21:" << entity21.name << endl;
    cout << "age21:" << entity21.age << endl;

    get_user22(entity2);
    cout << "name22:" << entity2.name << endl;
    cout << "age22:" << entity2.age << endl;

    // LoginEntity * entity3;
    // get_user3(entity3);
    // cout << "name3:" << entity3->name << endl;
    // cout << "age3:" << entity3->age << endl;
   
    LoginEntity * entity4 = get_user4();// 返回一级指针，这个可以
    cout << "name4:" << entity4->name << endl;
    cout << "age4:" << entity4->age << endl;
    delete entity4;

    LoginEntity * entity5;
    get_user5(&entity5);// 二级指针，这个可以
    cout << "name5:" << entity5->name << endl;
    cout << "age5:" << entity5->age << endl;
    delete entity5;

    return 0;
}